/*
 * c7_exercise8.cpp
 *
 *  Created on: Sep 2, 2013
 *      Author: cyper.yin
 */
#include <iostream>
using namespace std;

const int Seasons = 4;
const char *Snames[] = { "Spring", "Summer", "Fall", "Winter" };

//a.
void fill(double * expenses);
void show(const double * expenses);

//b.
struct SeasonExpenses{
	double expenses[Seasons];
};
void fill_SeasonExpenses(SeasonExpenses * p);
void show_SeasonExpenses(const SeasonExpenses * p);

int main_c7e8(int argc, char **argv) {

	//a.
	double expenses[Seasons];
	fill(expenses);
	show(expenses);

	cout << "============= Solution b ===============\n";
	//b.
	SeasonExpenses e;
	fill_SeasonExpenses(&e);
	show_SeasonExpenses(&e);

	return 0;
}

void fill(double * expenses) {
	for (int i = 0; i < Seasons; i++) {
		cout << "Enter " << Snames[i] << "'s expense:";
		cin >> expenses[i];
	}
}
void show(const double * expenses) {
	double total = 0.0;
	for (int i = 0; i < Seasons; i++) {
		cout << Snames[i] << "'s expense:" << expenses[i] << endl;
		total += expenses[i];
	}
	cout << "Total: " << total << endl;
}


void fill_SeasonExpenses(SeasonExpenses * p){
	for (int i = 0; i < Seasons; i++) {
			cout << "Enter " << Snames[i] << "'s expense:";
			cin >> p->expenses[i];
		}
}
void show_SeasonExpenses(const SeasonExpenses * p){
	double total = 0.0;
	for (int i = 0; i < Seasons; i++) {
		cout << Snames[i] << "'s expense:" << p->expenses[i] << endl;
		total +=  p->expenses[i];
	}
	cout << "Total: " << total << endl;

}

